﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Domain;
using SharedGenomics.Workbench.PresentationModel;

namespace SharedGenomics.Workbench.Tests.PresentationModel
{
    [TestClass]
    public class AnalysisResultDataColumnSchemaTests
    {
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowIfTypeNull()
        {
            var schema = new AnalysisResultDataColumnSchema(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void ConstructorShouldThrowIfTypeNotAnalysisResult()
        {
            var schema = new AnalysisResultDataColumnSchema(typeof(string));
        }

        [TestMethod]
        public void ShouldAddSnpPropertyIndex()
        {
            var schema = new AnalysisResultDataColumnSchema(typeof(FastEpistasisAnalysisResult));

            //add column for 'SnpName' property - this column has a snp attribute so should be added to the index
            schema.Add(new DataGridColumnInfo("Snp1", "SnpName", typeof(string)));
            Assert.AreEqual(1, schema.GetResultSnpProperties().Count());
            Assert.AreEqual(0, schema.GetResultSnpProperties().First().Key);
        }

        [TestMethod]
        public void ShouldNotAddPropertyIndex()
        {
            var schema = new AnalysisResultDataColumnSchema(typeof(FastEpistasisAnalysisResult));

            //add column for 'SnpName' property - this column does not have a snp attribute so should not be added to the index
            schema.Add(new DataGridColumnInfo("Chi Squared", "ChiSquared", typeof(string)));
            Assert.AreEqual(0, schema.GetResultSnpProperties().Count());
        }

        [TestMethod]
        public void ShouldReturnFalseIfNotSnpColumn()
        {
            var schema = new AnalysisResultDataColumnSchema(typeof(FastEpistasisAnalysisResult));
            schema.Add(new DataGridColumnInfo("Snp1", "SnpName", typeof(string)));

            Assert.IsTrue(schema.IsSnpColumn(0));
        }

        [TestMethod]
        public void ShouldReturnTrueIfSnpColumn()
        {
            var schema = new AnalysisResultDataColumnSchema(typeof(FastEpistasisAnalysisResult));
            schema.Add(new DataGridColumnInfo("Chi Squared", "ChiSquared", typeof(string)));

            Assert.IsFalse(schema.IsSnpColumn(0));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void ShouldThrowIfIndexNegative()
        {
            var schema = new AnalysisResultDataColumnSchema(typeof(FastEpistasisAnalysisResult));
            bool snpCol = schema.IsSnpColumn(-1);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void ShouldThrowIfIndexTooLarge()
        {
            var schema = new AnalysisResultDataColumnSchema(typeof(FastEpistasisAnalysisResult));
            bool snpCol = schema.IsSnpColumn(0);
        }
    }
}
